<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>个人中心</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        .el-header {
            line-height: 60px;
            color: #333;
            background-color: #B3C0D1;
            text-align: center;
        }

        .el-row {
            margin-bottom: 25px;
        }

        .el-card{
            background-color: #f0f9eb;
            weight:800px;
        }

        input {
            border: none;
            outline: none;
        }

        img {
            width: 160px;
            height: 130px;
            display: block;
            margin: 0 0 20px 40%;
            overflow: hidden;
            border: 1px solid #000;
            border-radius: 12px;
            border: none;
        }

        .img upload {
            width: 100%;
            text-align: center;
        }

        p {
            color: rgb(139, 138, 136);
            font-size: 14px;
        }
      </style>
</head>

<body>
<div id="app">
    <el-container>
        <el-header>个人中心</el-header>
        <el-main>
            <el-row style="text-align:right; margin-right: 100px;">
                <el-button @click='changefas'>编辑</el-button>
                <el-button @click='changetrue'>保存</el-button>
            </el-row>

            <el-row class="secrow">
                <el-col :span='16' :offset='4'>
                    <el-card>
                        <div class="img upload">
                            <img src="../image/defaultavatar.png" alt="" id="IsImgEmployeePicture"
                                 @click="chooseImageFile('EmployeePicture')">
                            <input type="file" name="fileEmployeeImage" id="EmployeePicture" accept="image/*" hidden
                                   @change='showImgToView("EmployeePicture")'>
                        </div>

                        <el-row>
                            <el-col :span='11' style="text-align: right">姓名</el-col>
                            <el-col :span='12' style="margin-left: 20px;">
                                <input type="text" v-model="name" :disabled='isCollapse' placeholder="请输入姓名">
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span='11' style="text-align: right">学号</el-col>
                            <el-col :span='12' style="margin-left: 20px;">
                                <input type="text" v-model="num" :disabled='isCollapse' placeholder="请输入学号">
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span='11' style="text-align: right">专业</el-col>
                            <el-col :span='12' style="margin-left: 20px;">
                                <input type="text" v-model='prof' :disabled='isCollapse' placeholder="请输入年级">
                            </el-col>
                        </el-row>

                    </el-card>
                </el-col>
            </el-row>

        </el-main>
    </el-container>
</div>

</body>

<script src="../js/vue.js"></script>
<script src="../js/jquery-1.11.0.min.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    //2、创建FileReader对象
    var fileReader = new FileReader();
    //正在判断是否符合图片类型
    regexImageFile = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i;
    var vue = new Vue({
        el: '#app',
        data: {
            name: '',
            num: '',
            prof: '',
            isCollapse: true
        },
        methods: {
            chooseImageFile(inputFileID) {
                console.log($('#' + inputFileID))
                $('#' + inputFileID).click();
            },
            showImgToView(inputFileId) {
                //选择图片文件，就是拿到上传的文件
                console.log($("#" + inputFileId).get(0).files[0]);
                var imgFile = $("#" + inputFileId).get(0).files[0];
                //判断上传文件是否为图片格式，这个type属性是file[0]对象自带的哈
                if (!regexImageFile.test(imgFile.type)) {
                    return;
                } else {
                    //将文件读取为DataURL
                    // 开始读取指定的Blob中的内容。一旦完成，result属性中将包含一个data: URL格式的Base64字符串以表示所读取文件的内容。
                    fileReader.readAsDataURL(imgFile);
                }
            },
            changefas() {
                this.isCollapse = false
            },
            changetrue() {
                this.isCollapse = true
            }

        }
    })
    // /4、读取文件
    fileReader.onload = function (evt) {
        //将该URL绑定到img标签的src属性上，就可以实现图片的上传预览效果
        $("#IsImgEmployeePicture").attr("src", evt.target.result);
    }
</script>

</html>